/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package cn.newtest.bi.collection.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * 报告期实例表
 *
 * @author <a href="mailto: chenjian@risesoft.net">陈健</a>
 * @version $Revision$
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="Rpt_ReportPeriod")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class ReportPeriod implements Comparable<Object>, Serializable {
	
	private static final long serialVersionUID = -3217077045501802551L;

	@Id
	@Column(name="ReportPeriod_guid",length=38)
	@GenericGenerator(name="ReportPeriod-assigned",strategy="assigned")
	private String guid;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ReportPeriod_Type_GUID",nullable=true)
	private ReportPeriodType reportPeriodType;
	
	@Column(name="ReportPeriod_code",length=64)
	private String code;
	
	@Column(name="ReportPeriod_name",length=64)
	private String name;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="ReportPeriod_timetype")
	private Date timetype;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date begin_time;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date end_time;
	
	@Basic
	private Integer duration;
	
	@Basic
	private Integer order_in_year;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="service_guid",nullable=true)
	private Service service;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Parent_term_guid",nullable=true)
	private ReportPeriod parent_term;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Previous_term_guid",nullable=true)
	private ReportPeriod previous_term;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Lastyear_term_guid",nullable=true)
	private ReportPeriod lastyear_term;
	
	@Transient
	public String getReportPeriodTypeGuid() {
		if(reportPeriodType != null){
			return reportPeriodType.getGuid();
		}
		return "";
	}
	
	public void setReportPeriodTypeGuid(String reportPeriodTypeGuid) {
		if(reportPeriodTypeGuid != null && reportPeriodTypeGuid.trim().length()>0){
			if(reportPeriodType==null){
				reportPeriodType = new ReportPeriodType();
				reportPeriodType.setGuid(reportPeriodTypeGuid);
			}
		}
	}
	
	@Transient
	public String getParent_termGuid() {
		if(parent_term != null){
			return parent_term.getGuid();
		}
		return "";
	}
	
	public void setParent_termGuid(String parentGuid) {
		if(parentGuid != null && parentGuid.trim().length()>0){
			if(parent_term==null){
				parent_term = new ReportPeriod();
				parent_term.setGuid(parentGuid);
			}
		}
	}
	
	@Transient
	public String getPrevious_termGuid() {
		if(previous_term != null){
			return previous_term.getGuid();
		}
		return "";
	}
	
	public void setPrevious_termGuid(String parentGuid) {
		if(parentGuid != null && parentGuid.trim().length()>0){
			if(previous_term==null){
				previous_term = new ReportPeriod();
				previous_term.setGuid(parentGuid);
			}
		}
	}
	
	@Transient
	public String getLastyear_termGuid() {
		if(lastyear_term != null){
			return lastyear_term.getGuid();
		}
		return "";
	}
	
	public void setLastyear_termGuid(String parentGuid) {
		if(parentGuid != null && parentGuid.trim().length()>0){
			if(lastyear_term==null){
				lastyear_term = new ReportPeriod();
				lastyear_term.setGuid(parentGuid);
			}
		}
	}
	
	public Service getService() {
		return service;
	}
	public void setService(Service service) {
		this.service = service;
	}
	
	public Date getBegin_time() {
		return begin_time;
	}

	public void setBegin_time(Date begin_time) {
		this.begin_time = begin_time;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public Date getEnd_time() {
		return end_time;
	}

	public void setEnd_time(Date end_time) {
		this.end_time = end_time;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public ReportPeriod getLastyear_term() {
		return lastyear_term;
	}

	public void setLastyear_term(ReportPeriod lastyear_term) {
		this.lastyear_term = lastyear_term;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getOrder_in_year() {
		return order_in_year;
	}

	public void setOrder_in_year(Integer order_in_year) {
		this.order_in_year = order_in_year;
	}

	public ReportPeriod getParent_term() {
		return parent_term;
	}

	public void setParent_term(ReportPeriod parent_term) {
		this.parent_term = parent_term;
	}

	public ReportPeriod getPrevious_term() {
		return previous_term;
	}

	public void setPrevious_term(ReportPeriod previous_term) {
		this.previous_term = previous_term;
	}

	public ReportPeriodType getReportPeriodType() {
		return reportPeriodType;
	}

	public void setReportPeriodType(ReportPeriodType reportPeriodType) {
		this.reportPeriodType = reportPeriodType;
	}

	public Date getTimetype() {
		return timetype;
	}

	public void setTimetype(Date timetype) {
		this.timetype = timetype;
	}

	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(Object object) {
		ReportPeriod myClass = (ReportPeriod) object;
		return new CompareToBuilder().append(this.begin_time,
				myClass.begin_time).append(this.code, myClass.code)
				.append(
						this.guid, myClass.guid).append(this.order_in_year,
						myClass.order_in_year).append(this.duration,
						myClass.duration).append(this.end_time,
						myClass.end_time).append(this.name, myClass.name)
				.append(this.timetype, myClass.timetype).toComparison();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof ReportPeriod)) {
			return false;
		}
		ReportPeriod rhs = (ReportPeriod) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(this.begin_time,
				rhs.begin_time).append(this.code, rhs.code).append(this.guid, rhs.guid).append(
				this.order_in_year, rhs.order_in_year).append(this.duration,
				rhs.duration).append(this.end_time, rhs.end_time).append(
				this.name, rhs.name).append(this.timetype, rhs.timetype)
				.isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(128477089, -979080413).appendSuper(
				super.hashCode())
				//.append(this.lastyear_term)
				.append(
				this.begin_time)
				.append(this.code).append(this.guid).append(
						this.order_in_year).append(this.duration).append(
						this.end_time).append(this.name).append(this.timetype)
				//.append(this.parent_term)
				.toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("order_in_year",
				this.order_in_year).append("end_time", this.end_time).append("timetype", this.timetype).append(
				"code", this.code)
				.append("duration", this.duration).append("guid", this.guid)
				.append("name", this.name)
				.append("begin_time", this.begin_time).toString();
	}
}